<template>
	<view class="index-main-style" style="background-color: #FFFFFF;">
		<cu-custom v-if="loginIsBack" bgColor="bg-gradual-pink" isBack>
			<block slot="content"><text class="text-xl">重新登录</text></block>
		</cu-custom>
		<!-- <view class="text-right text-grey padding-lr text-bold" style="position: absolute;top: 10vh;right: 1vw;">
			<text>版本号：{{vesion}}{{baseUrl == 'http://172.22.50.8:9902/'?'(测试版)':''}}</text>
		</view> -->
		<view class="login-title-view text-center" style="height: 50vh;">
			<view class="login-title-img">
				<image mode="widthFix" style="width: 80%;" src="../../static/logo.png"></image>
			</view>

		</view>
		<view class="task-login-middle">
			<view class="task-login-inputList flex flex-direction justify-center align-center">
				<view class="task-login-input solids" :style="codeInput?'':'border: 2rpx solid red;'">
					<image style="width: 50rpx;height:50rpx" src="../../static/user.png"></image>
					<view class="task-login-placeholder-class margin-left-sm">
						<input placeholder="请输入租户号" placeholder-class="task-login-placeholder" v-model="obj.loginCode"
							:placeholder-class="codeInput?'':'task-login-inputcolor'" />
					</view>
				</view>
				<view class="task-login-input solids task-login-input-if"
					:style="accountInput?'':'border: 2rpx solid red;'">
					<image style="width: 50rpx;height:50rpx" src="../../static/user.png"></image>
					<view class="task-login-placeholder-class margin-left-sm">
						<input placeholder="请输入账号" placeholder-class="task-login-placeholder" v-model="obj.loginName"
							:placeholder-class="accountInput?'':'task-login-inputcolor'" />
					</view>
				</view>
				<view class="task-login-input solids task-login-input-if"
					:style="passInput?'':'border: 2rpx solid red;'">
					<image style="width: 50rpx;height:50rpx" src="../../static/lock.png"></image>
					<view class="task-login-placeholder-class margin-left-sm">
						<input style="border: 0;" placeholder="请输入密码" placeholder-class="task-login-placeholder"
							v-model="obj.password" :type="isPassword?'password':'text'"
							:placeholder-class="passInput?'':'task-login-inputcolor'" />
					</view>
					<text @touchstart="isPasswordShow" @touchend="isPasswordShow"
						:class="[isPassword?'icon-attention':'icon-attentionfill']" style="font-size: 45rpx;"></text>
				</view>
				<view class="flex justify-between align-center padding-tb" style="width: 70vw;">
					<text class="text-blue">记住账号</text>
					<switch class='red' @change="changeSwitch" :class="switchB?'checked':''"
						:checked="switchB?true:false"></switch>
				</view>
				<view class="task-login-sub task-login-input-if">
					<button @click="sub(0)" :disabled="obj.loading"
						:loading="obj.loading">{{ obj.loading ? "登录中...":"登录系统 >>"}}</button>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import Base64 from '../../common/base64.js';
	const base = new Base64();
	import helper from '../../common/helper.js';
	import api from '../../api/api.js';
	import {
		deepClone
	} from '../../common/base.js';
	var app = null;
	var loactionTimer = null;
	export default {
		data() {
			return {
				baseUrl: this.$api._baseUrl,
				loginIsBack: this.$helper.loginIsBack,
				vesion: this.$helper.vesion,
				switchB: true,
				isPassword: true,
				locationData: {},
				user: {
					loginName: 'admin11',
					password: '123456'
				},
				codeInput: true,
				accountInput: true,
				passInput: true,
				obj: {
					loginCode: this.$helper.tenantId,
					loading: false,
					loginName: '',
					password: ''
				}
			}
		},
		onLoad(option) {
			app = new api();
			var that = this;
			let userInfo = uni.getStorageSync('userInfo');
			if (userInfo) {
				that.obj = userInfo;
				that.switchB = userInfo.switchB;
			}
		},
		methods: {
			gotoCeshiLocaltion() {
				uni.navigateTo({
					url: '../test-page/index'
				})
			},
			changeSwitch() {
				this.switchB = !this.switchB;
			},
			isPasswordShow() {
				this.isPassword = !this.isPassword;
			},
			gotoLocation() {
				var that = this;
				uni.redirectTo({
					url: '../test-warehouse/index'
				})
			},
			gotoTestMap() {
				uni.navigateTo({
					url: '../test-page/index'
				})
			},
			// repairMessage(userId) {
			// 	var that = this;
			// 	that.$api.repairMessage({
			// 		userId
			// 	}).then(res => {
			// 		if (res.code == 0) {
			// 			that.$
			// 		}
			// 	}).catch(error => {
			// 		uni.showToast({
			// 			title: '消息推送请求异常',
			// 			icon: 'none'
			// 		})
			// 	})
			// },
			// getAuth(key) {
			// 	console.log(key)
			// 	this.$api.postAPI('/auth/api/currentUserPermissions?serviceId=' + key, {}, res => {
			// 		console.log(res, '+++')
			// 	})
			// },
			sub(type) {
				var that = this;
				that.obj.loading = true;
				if (that.obj.loginCode == '') {
					that.codeInput = false;
					uni.showToast({
						title: '请输入租户号',
						icon: 'none'
					})
					that.obj.loading = false;
					return false;
				} else {
					that.codeInput = true;
				}
				if (that.obj.loginName == '') {
					that.accountInput = false;
					uni.showToast({
						title: '请输入用户名',
						icon: 'none'
					})
					that.obj.loading = false;
					return false;
				} else {
					that.accountInput = true;
				}
				if (that.obj.password == '') {
					that.passInput = false;
					uni.showToast({
						title: '请输入密码',
						icon: 'none'
					})
					that.obj.loading = false;
					return false;
				} else {
					that.passInput = true;
				}
				let loginData = {
					tenantId: that.obj.loginCode,
					loginName: that.obj.loginName,
					password: that.obj.password,
					containServiceList: true,
					getOSS: true,
					loginType: 'NAME_PASSWORD'
				}
				app.userlogin(loginData).then(res => {
					if (res.code == 0) {
						that.obj.loading = false;
						helper.serviceId = res.data.serviceList[0].id
						helper.userInfo = res.data.userVO;
						helper.token = res.data.authToken;
						let obj = that.obj;
						obj.switchB = that.switchB;
						if (that.switchB) {
							uni.setStorageSync('userInfo', obj);
						} else {
							let obj = that.obj;
							obj.password = '';
							obj.loginName = '';
							uni.setStorageSync('userInfo', obj);
						}
						if (that.loginIsBack) {
							that.$helper.loginIsBack = false;
							uni.navigateBack()
						} else {
							// #ifdef APP-PLUS
							// that.$startTimer(helper.userInfo.id);
							// #endif
							uni.reLaunch({
								url: '../menu/menu'
							})
						}
						// })
					} else {
						uni.showToast({
							title: JSON.stringify(res.message),
							icon: 'none'
						})
						that.obj.loading = false;
					}
				})
			},
		}
	}
</script>

<style>
	input {
		border-width: 0;
	}

	.login-title-view {
		position: relative;
		width: 100%;
		height: 30vh;
		display: flex;
		align-items: center;
		flex-direction: column;
	}

	.login-title-img {
		width: 100vw;
		margin-top: 15vh;
		/* height: 24vh; */
		/* 	width: 20vw;
		height: 20vw;
		background: #FFFFFF;
		border-radius: 50%;
		margin-top: 25vh; */
		/* left: 50vh; */
	}

	.login-title-img>image {
		width: 100%;
		height: 100%;
	}

	.task-login-sub>button {
		height: 6vh;
		width: 70vw;
		line-height: 6vh;
		color: #ffffff;
		font-size: 28upx;
		border-radius: 10upx;
		outline: 0;
		display: block;
		margin: 0;
		font-family: inherit;
		background: rgb(64, 158, 255);
		/* opacity: 0.8; */
	}

	.task-login-title {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 10upx 20upx;
	}

	.login-choose-area {
		width: 504upx;
	}

	.task-login-inputcolor {
		color: red;
	}

	.task-login-placeholder-class>input {
		width: 100%;
		font-size: 24upx;
	}

	.task-login-placeholder-class {
		width: 70%;
	}

	.task-login-placeholder {
		color: #cecece;
		font-size: 20.9upx;
	}

	.task-login-sub {
		height: 5vh;
		border-radius: 10upx;
		display: flex;
		justify-content: center;
		align-items: center;
		color: #FFFFFF;
	}

	.task-login-input-text {
		display: flex;
		justify-content: space-between;
		margin-top: 24upx;
		padding: 0 20upx 0;
		font-size: 20.9upx;
		color: #FFFFFF;
		margin-bottom: 76upx;
	}

	.task-login-pass {
		height: 40upx;
		width: 30upx;
	}

	.task-login-account {
		width: 42upx;
		height: 32upx;
	}

	.task-login-input {
		border-radius: 10rpx;
		background-color: #FFFFFF;
		display: flex;
		align-items: center;
		/* justify-content: center; */
		padding: 20rpx 30rpx;
		width: 70vw;
	}

	.task-login-input-if {
		margin-top: 5vh;
	}

	.task-login-middle {
		display: flex;
		justify-content: center;
	}

	.task-login-index {
		margin-top: 20vh;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
	}

	.task-login-image {
		/* padding: 199upx 199upx 0; */
		height: 349upx;
		width: 349upx;
	}

	.task-login-image>image {
		height: 100%;
		width: 100%;
	}

	.task-login-inputList {
		width: 100vw;
	}
</style>